<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link href="{{ asset('AdminPublic/static/h-ui/css/H-ui.min.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('AdminPublic/static/h-ui.admin/css/H-ui.admin.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('AdminPublic/lib/Hui-iconfont/1.0.8/iconfont.css') }}" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script><![endif]-->
<title>用户查看</title>
</head>
<body>

<article class="cl pd-20">
  <div style="padding-top:50px;margin-left:97px;">
		@foreach ($discount as $k => $v)
		@if ($k == '1')
			<div class="row cl">
        <div class="formControls col-xs-8 col-sm-9">
					普通会员：
					<i style="cursor:pointer;" onclick="addnumber(this, '{{ $k }}')" class="Hui-iconfont">&#xe600;</i>
					<input type="text" class="input-text" readonly unselectable="on" value="{{ $v }}折" id="{{ $k }}" name="discount" style="width:50px;text-align:center;background:#ccc;">
					<i style="cursor:pointer;" onclick="reduce(this, '{{ $k }}')" class="Hui-iconfont">&#xe6a1;</i>
				</div>
			</div>
		@else
			<div class="row cl">
        <div class="formControls col-xs-8 col-sm-9">
					@if($k == '2')
						黄金会员：
					@else
						钻石会员：
					@endif
					<i style="cursor:pointer;" onclick="addnumber(this, '{{ $k }}')" class="Hui-iconfont">&#xe600;</i>
					<input type="text" class="input-text"  readonly unselectable="on" value="{{ $v }}折" id="{{ $k }}" name="discount" style="width:50px;text-align:center;">
					<i style="cursor:pointer;" onclick="reduce(this, '{{ $k }}')" class="Hui-iconfont">&#xe6a1;</i>
				</div>
			</div>
		@endif
		@endforeach
  </div>

	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input style="margin-left:20px;" id="submit" class="btn btn-get btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="{{ asset('AdminPublic/lib/jquery/1.9.1/jquery.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('AdminPublic/lib/layer/2.4/layer.js') }}"></script>
<script type="text/javascript" src="{{ asset('AdminPublic/static/h-ui/js/H-ui.js') }}"></script>
<script type="text/javascript" src="{{ asset('AdminPublic/static/h-ui.admin/js/H-ui.admin.page.js') }}"></script>
<!--/_footer /作为公共模版分离出去-->
<script>

// 加
function addnumber(tag, key)  {
		var number = $(tag).next().val();

		var string = number.substr(number.length - 1, number.length);
		console.log(string);
		if (string == '折') {
				number = number.substr(0, number.length - 1);
		}


		number = Number(number);

		number++;

		if (number > 100) {
				$(tag).next().val('100折');
		} else {
				$(tag).next().val(number + '折');
		}
}

// 减
function reduce(tag, key) {

		var number = $(tag).parent().children().first().next().val();
		var string = number.substr(number.length - 1, number.length);
		if (string == '折') {
				number = number.substr(0, number.length - 1);
		}


		number = Number(number);
		number--;

		if (number < 95) {
				$(tag).parent().children().first().next().val('95折')
		} else {
			console.log(number);
				$(tag).parent().children().first().next().val(number + '折');
		}

}

// 提交
$('#submit').click(function() {

    var generalmember = $('#1').val();
    var goldmember = $('#2').val();
    var diamond = $('#3').val();

    var generalmember = generalmember.substr(0, generalmember.length - 1);

    var goldmember = goldmember.substr(0, goldmember.length - 1);

    var diamond = diamond.substr(0, diamond.length - 1);

    $.ajax({
        type: 'post',
        url: "{{ route('member.discountchange') }}",
        data: "generalmember="+ generalmember + "&goldmember="+ goldmember + "&diamond="+ diamond + "&_token={{ csrf_token() }}",
        success: function(data){
          if (data == 200) {
              layer.msg('修改成功!',{icon:1,time:1000});
              setTimeout(function(){
                  var index = parent.layer.getFrameIndex(window.name);
                  parent.$('.btn-refresh').click();
                  parent.layer.close(index);
              },1200);
          } else if (data == 500) {
              layer.msg('修改失败，请输入正确的折扣!',{icon:2,time:1000});
          }
        },
        error: function(XmlHttpRequest, textStatus, errorThrown){
          layer.msg('修改失败!',{icon:2,time:1000});
        }
    });

});
</script>

</body>
</html>
